home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / tags18.zip / STD.H < prev    next >
C/C++ Source or Header  |  1991-09-04  |  4KB  |  162 lines

  1. /* std.h - automagically adapt to old and new compilers.
  2.    In the Public Domain; written by Mike Haertel. */
  3.  
  4. /* MS-DOS port (c) 1990 by Thorsten Ohl, td12@ddagsi3.bitnet
  5.    This port is distributed under the terms of the
  6.    GNU General Public License as published by the
  7.    Free Software Foundation.
  8.  
  9.    $Header: e:/gnu/sort/RCS/std.h'v 0.3.0.2 90/08/26 19:03:25 tho Exp $
  10.  */
  11.  
  12. #if __STDC__
  13.  
  14. #include <stddef.h>
  15. #include <limits.h>
  16.  
  17. typedef void *PTR;
  18. typedef const void *PTRCONST;
  19.  
  20. #define AND ,
  21. #define DEFUN(F, L, P) F(P)
  22. #define EXFUN(F, P) F P
  23.  
  24. #else
  25.  
  26. #define const
  27. #define volatile
  28.  
  29. /* The following approximations of <stddef.h> and <limits.h> are appropriate
  30.    for most machines. */
  31. typedef int ptrdiff_t;
  32. typedef unsigned int size_t;
  33. #define NULL 0
  34. #define offsetof(T, M) ((size_t)&((T *) 0)->(M))
  35.  
  36. #define CHAR_BIT 8
  37. #define SCHAR_MIN -128
  38. #define SCHAR_MAX 127
  39. #define UCHAR_MAX 255
  40. #define CHAR_MIN ((char) UCHAR_MAX < 0 ? SCHAR_MIN : 0)
  41. #define CHAR_MAX ((char) UCHAR_MAX < 0 ? SCHAR_MAX : UCHAR_MAX)
  42. #define SHRT_MIN -32768
  43. #define SHRT_MAX 32767
  44. #define USHRT_MAX 65535
  45. #define INT_MIN (sizeof (int) == 2 ? -32768 : -2147483648)
  46. #define INT_MAX (sizeof (int) == 2 ? 32767 : 2147483647)
  47. #define UINT_MAX (sizeof (int) == 2 ? 65535 : 4294967295)
  48. #define LONG_MIN -2147483648L
  49. #define LONG_MAX 2147483647L
  50. #define ULONG_MAX 4294967295
  51.  
  52. typedef char *PTR;
  53. typedef const char *PTRCONST;
  54.  
  55. #define AND ;
  56. #define DEFUN(F, L, P) F L P ;
  57. #define EXFUN(F, P) F()
  58.  
  59. #endif
  60.  
  61. /* Deal with <ctype.h> lossage. */
  62. #include <ctype.h>
  63.  
  64. #ifndef isascii
  65.  
  66. #define ISALNUM(C) isalnum(C)
  67. #define ISALPHA(C) isalpha(C)
  68. #define ISCNTRL(C) iscntrl(C)
  69. #define ISDIGIT(C) isdigit(C)
  70. #define ISGRAPH(C) isgraph(C)
  71. #define ISLOWER(C) islower(C)
  72. #define ISPRINT(C) isprint(C)
  73. #define ISPUNCT(C) ispunct(C)
  74. #define ISSPACE(C) isspace(C)
  75. #define ISUPPER(C) isupper(C)
  76. #define ISXDIGIT(C) isxdigit(C)
  77. #define TOLOWER(C) tolower(C)
  78. #define TOUPPER(C) toupper(C)
  79.  
  80. #else
  81.  
  82. #define ISALNUM(C) (isascii(C) && isalnum(C))
  83. #define ISALPHA(C) (isascii(C) && isalpha(C))
  84. #define ISCNTRL(C) (isascii(C) && iscntrl(C))
  85. #define ISDIGIT(C) (isascii(C) && isdigit(C))
  86. #define ISGRAPH(C) (isascii(C) && isgraph(C))
  87. #define ISLOWER(C) (isascii(C) && islower(C))
  88. #define ISPRINT(C) (isascii(C) && isprint(C))
  89. #define ISPUNCT(C) (isascii(C) && ispunct(C))
  90. #define ISSPACE(C) (isascii(C) && isspace(C))
  91. #define ISUPPER(C) (isascii(C) && isupper(C))
  92. #define ISXDIGIT(C) (isascii(C) && isxdigit(C))
  93. #define TOLOWER(C) (ISUPPER(C) ? tolower(C) : (C))
  94. #define TOUPPER(C) (ISLOWER(C) ? toupper(C) : (C))
  95.  
  96. #endif
  97.  
  98. /* Declaring this here should be safe.  Some losing <errno.h>'s don't. */
  99. #ifndef MSDOS
  100. extern int errno;
  101. #endif /* not MSDOS */
  102.  
  103. /* Adapt variable arguments to new implementations (with <stdarg.h>)
  104.    or old (which are assumed to have <varargs.h>). */
  105.  
  106. #if __STDC__
  107.  
  108. #include <stdarg.h>
  109.  
  110. #define VA_ALIST ...
  111. #define VA_DCL ...
  112. #define VA_LIST va_list
  113. #define VA_START(AP, LASTARG) va_start(AP, LASTARG)
  114. #define VA_ARG(AP, TYPE) va_arg(AP, TYPE)
  115. #define VA_END(AP) va_end(AP)
  116.  
  117. #define VA_DEFUN(F, L, P) F(P)
  118.  
  119. #else
  120.  
  121. #include <varargs.h>
  122.  
  123. #define VA_ALIST va_alist
  124. #define VA_DCL va_dcl
  125. #define VA_LIST va_list
  126. #define VA_START(AP, LASTARG) va_start(AP)
  127. #define VA_ARG(AP, TYPE) va_arg(AP, TYPE)
  128. #define VA_END(AP) va_end(AP)
  129.  
  130. #define VA_DEFUN(F, L, P) F L P
  131.  
  132. #endif
  133.  
  134. /* Declarations of traditional library routines. */
  135. #ifdef MSDOS
  136. #include <stdlib.h>
  137. extern void *xmalloc (size_t size);
  138. extern void *xrealloc (void *ptr, size_t size);
  139. #else /* not MSDOS */
  140. extern double EXFUN(atof, (const char *));
  141. extern int EXFUN(atoi, (const char *));
  142. extern long int EXFUN(atol, (const char *));
  143. extern int EXFUN(rand, (void));
  144. extern void EXFUN(srand, (int));
  145. extern PTR EXFUN(calloc, (size_t, size_t));
  146. extern void EXFUN(free, (PTR));
  147. extern PTR EXFUN(malloc, (size_t));
  148. extern PTR EXFUN(realloc, (PTR, size_t));
  149. extern void EXFUN(abort, (void));
  150. extern void EXFUN(exit, (int));
  151. extern char *EXFUN(getenv, (const char *));
  152. extern int EXFUN(system, (const char *));
  153. extern void EXFUN(qsort, (PTR, size_t, size_t,
  154.               int EXFUN((*), (PTRCONST, PTRCONST))));
  155. extern int EXFUN(abs, (int));
  156. extern long int EXFUN(labs, (long int));
  157.  
  158. #ifdef X_strerror
  159. extern char *EXFUN(strerror, (int));
  160. #endif
  161. #endif /* not MSDOS */
  162.